package geditor {
import flash.events.Event;

import geditor.common.DrawComponentFactory;

import mx.controls.Button;

public class CompFactoryListener {
    private var tool:DrawTool;
    private var factory:DrawComponentFactory;
    private var btn:Button;

    public function CompFactoryListener(tool:DrawTool, factory:DrawComponentFactory, btn:Button) {
        this.tool = tool;
        this.factory = factory;
        this.btn = btn;
    }

    public function listen(evt:Event):void {
        if (!btn.selected) {
            tool.finishCreating(false);
        } else {
            tool.startCreating(factory.newComponent());
            tool.addEventListener("finishCreate", function(evt:Event):void {
                btn.selected = false;
            });
        }
    }
}
}